<template>
    <div>
        <div class="btn1">
            <div>咨询师名称</div>
            <el-input style="width: 200px;margin-left: 10px;" v-model="input" placeholder="请输入公益名称"></el-input>
            <!-- 搜索按钮 -->
            <el-button @click="searchByName()" style="margin-left: 20px;" type="primary">搜索</el-button>
        </div>
<!--        &lt;!&ndash;        新增小区    &ndash;&gt;-->
        <div class="addBtn">
            <el-button type="text" @click="dialogFormVisible = true">新增公益</el-button>

            <el-dialog title="新增咨询师" :visible.sync="dialogFormVisible">
                <el-form :model="form">
                    <el-form-item label="名字" :label-width="formLabelWidth">
                        <el-input v-model="form.name" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="头像" :label-width="formLabelWidth">

                        <el-upload
                                action="http://localhost:8080/free/upload"
                                list-type="picture-card"
                                :on-success="uploadImg"
                                :on-preview="handlePictureCardPreview"
                                :on-remove="handleRemove">
                            <i class="el-icon-plus"></i>
                        </el-upload>
                        <el-dialog :visible.sync="dialogVisible">
                            <img width="100%" :src="dialogImageUrl" alt="">
                        </el-dialog>
                    </el-form-item>

                    <el-form-item label="地址" :label-width="formLabelWidth">
                        <el-input v-model="form.address" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="简介" :label-width="formLabelWidth">
                        <el-input v-model="form.intro" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="认证状态" :label-width="formLabelWidth">
                        <el-select v-model="form.region" placeholder="请选择">
                            <el-option label="已认证" value="已认证"></el-option>
                            <el-option label="未认证" value="未认证"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="等级" :label-width="formLabelWidth">
                        <el-input v-model="form.levelname" autocomplete="off"></el-input>

                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="dialogFormVisible = false">取 消</el-button>
                    <el-button type="primary" @click="addFree">确 定</el-button>
                </div>
            </el-dialog>
        </div>

<!--        &lt;!&ndash;//编辑公益表格&ndash;&gt;-->
        <el-dialog title="编辑咨询师" :visible.sync="dialogFormVisible1">
            <el-form :model="form1">
                <el-form-item label="名字" :label-width="formLabelWidth">
                    <el-input v-model="form1.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="头像" :label-width="formLabelWidth">

                    <el-upload
                            action="http://localhost:8080/free/upload"
                            list-type="picture-card"
                            :on-success="uploadImg"
                            :on-preview="handlePictureCardPreview"
                            :on-remove="handleRemove">
                        <i class="el-icon-plus"></i>
                    </el-upload>
                    <el-dialog :visible.sync="dialogVisible1">
                        <img width="100%" :src="dialogImageUrl1" alt="">
                    </el-dialog>
                </el-form-item>

                <el-form-item label="简介" :label-width="formLabelWidth">
                    <el-input v-model="form1.intro" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="地址" :label-width="formLabelWidth">
                    <el-input v-model="form1.address" autocomplete="off"></el-input>
                </el-form-item>



            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible1 = false">取 消</el-button>
                <el-button type="primary" @click="updateFree()">确 定</el-button>
            </div>
        </el-dialog>



        <!-- 表格 -->
        <el-table
                :data="tableData"
                border
                style="width: 100%">
            <el-table-column
                    fixed
                    prop="id"
                    label="id"
                    width="150">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="用户名"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="image"
                    label="头像"
                    width="120">
                <template slot-scope="scope">
                    <img :src="scope.row.image" alt="图片" style="width: 100px; height: auto;"/>
                </template>
            </el-table-column>
            <el-table-column
                    prop="address"
                    label="昵称"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="intro"
                    label="个人简介"
                    width="300">
            </el-table-column>
            <el-table-column
                    prop="authentication"
                    label="authentication"
                    width="120">

            </el-table-column>
            <el-table-column
                    prop="levelName"
                    label="咨询师等级"
                    width="120">

            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作"
                    width="100">
                <template slot-scope="scope">
                    <el-button @click="searchMessageById(scope.$index)" type="text" size="small">编辑</el-button>


                    <el-button type="text" size="small" @click="remove(scope.$index)" >删除</el-button>
                </template>
            </el-table-column>
        </el-table>


        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage2"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
        >
        </el-pagination>

    </div>
</template>

<script>
    export default {
        name: "zixunshiguanli",
data(){
            return{
                dialogFormVisible1:false,
                tableData: [],
                input: "",
                dialogFormVisible: false,
                currentPage2:1,
                pageNum: 1,
                pageSize:5,
                form: {
                    address:"",
                    region:"",
                    intro:"",
                    name: "",
                    levelname:""
                },
                //证书数组
                gridData:[],
                // 证书弹框显示
                dialogTableVisible3:false,
                form1: {
                    address:"",
                    region:"",
                    intro:"",
                    name: "",
                    levelname:""
                },
                dialogImageUrl1: '',
                dialogVisible1: false,
                disabled1: false,
                //    图像
                dialogImageUrl: '',
                dialogVisible: false,
                disabled: false,
            }
},

methods:{
    //        分页
    handleSizeChange(val) {
        this.pageSize= val;
        this.axios.get("/teacher/teacherlist",{
            params: {
                pageNum:this.currentPage2,
                pageSize:this.pageSize,
            },
        }).then((res)=>{
            this.tableData = res.data.data
            console.log(this.tableData)
        })
    },
    handleCurrentChange(val) {
        this.currentPage2=val;
        this.axios.get("/teacher/teacherlist",{
            params: {
                pageNum:this.currentPage2,
                pageSize:this.pageSize,
            },
        }).then((res)=>{
            this.tableData = res.data.data
            console.log(this.tableData)
        })
    },
    //编辑
    searchMessageById(index){
        this.dialogFormVisible1=true
        this.form1.name=this.tableData[index].name
        this.form1.address = this.tableData[index].address
        this.form1.intro = this.tableData[index].intro
        this.form1.id=this.tableData[index].id
        this.form1.region = this.tableData[index].region
        this.form1.levelname=this.tableData[index].levelname
    },
    //修改公益信息
    updateFree(){
        this.dialogFormVisible1=false
        this.axios.post("/teacher/updatezixunshi",{
            id:  this.form1.id,
            name:    this.form1.name,
            address:  this.form1.address,
            intro: this.form1.intro,
            levelname:this.form1.levelname



        }).this.axios.get("/teacher/teacherlist",{
            params: {
                pageNum:this.currentPage2,
                pageSize:this.pageSize,
            },
        }).then((res)=>{
            this.tableData = res.data.data
            console.log(this.tableData)
        })
    },
    //查看咨询师证书
    findbook(index){
        this.dialogTableVisible3=true;
        this.axios.get("/teacher/selectAllTeacherBook").then((res)=>{
            this.gridData = res.data.data
        })
    },
    //图像
    handleRemove(file) {
        console.log(file);
    },
    handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
    },
    handleDownload(file) {
        console.log(file);
    },
    uploadImg(r){
        console.log(r.data);
        this.tableData.image="http://localhost:8080/free/down?filename="+r.data;
        console.log(this.tableData.image)
    },


    //添加公益
    addFree() {
        this.dialogFormVisible = false
        this.axios.post("/teacher/addzixuanshi",  {
            // form: {
            //     address:"",
            //     region:"",
            //     intro:"",
            //     name: "",
            //
            // },

            intro: this.form.intro,
            image: this.tableData.image,
            region: this.form.region,
            name: this.form.name,
            address: this.form.address,
            levelName:this.form.levelname
        }).then((res) => {
            console.log(res.data.data)
            this.tableData = res.data.data

        }).this.axios.get("/teacher/teacherlist",{
            params: {
                pageNum:this.currentPage2,
                pageSize:this.pageSize,
            },
        }).then((res)=>{
            this.tableData = res.data.data
            console.log(this.tableData)
        })
    },
           // 搜索
    searchByName() {
        this.axios.get("/teacher/Liketeacher", {
            params: {
                name: this.input
            }
        }).then((res) => {
            this.tableData = res.data.data
        })
    },

    //    删除
    remove(index) {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            this.axios.delete("/teacher/delzixunshi", {
                params: {
                    id: this.tableData[index].id
                }
            })
            this.$message({
                type: 'success',
                message: '删除成功!'
            });
        }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消删除'
            });
        }).this.axios.get("/teacher/teacherlist",{
            params: {
                pageNum:this.currentPage2,
                pageSize:this.pageSize,
            },
        }).then((res)=>{
            this.tableData = res.data.data
            console.log(this.tableData)
        })
    },
},







        created() {
            this.axios.get("/teacher/teacherlist",{
                params: {
                    pageNum:this.currentPage2,
                    pageSize:this.pageSize,
                },
            }).then((res)=>{
                this.tableData = res.data.data
                console.log(this.tableData)
            })
        }
    }
</script>

<style scoped>

</style>